package com.sugar.web.struts.system.privilege;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sugar.domain.system.privilege.PrivilegeRole;
import com.sugar.service.system.privilege.IPrivilegeResourceModelService;
import com.sugar.service.system.privilege.IPrivilegeRoleService;
import com.sugar.web.struts.BaseActionSupport;

@Controller
@Scope("prototype")
public class PrivilegeRoleAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;
	
	private PrivilegeRole rolevo ;
	
	private String resourceIds ;
	
	public String getResourceIds() {
		return resourceIds;
	}

	public void setResourceIds(String resourceIds) {
		this.resourceIds = resourceIds;
	}

	public PrivilegeRole getRolevo() {
		return rolevo;
	}

	public void setRolevo(PrivilegeRole rolevo) {
		this.rolevo = rolevo;
	}

	@Resource
	private IPrivilegeRoleService roleService ;
	
	@Resource
	private IPrivilegeResourceModelService modelService ;
	
	public String queryAll() throws Exception {
		
		this.getRequest().setAttribute("privilegeRole", this.roleService.findPrivilegeRoleService(null)) ;
		
		return "queryall" ;
	}
	
	public String loadRoleToResItem() throws Exception {
		
		this.getRequest().setAttribute("resItem", this.roleService.loadPrivilegeRoleByIdService(rolevo.getR_id())) ;
		
		return "queryByResItem" ;
	}
	
	public String resourceAssign() throws Exception {
		
		getRequest().setAttribute("role", this.roleService.findPrivilegeRoleService(null)) ;
		
		getRequest().setAttribute("model",this.modelService.findPRModelService(null)) ;
		
		return "assign" ;
	}
	
	public String updateRoleAssignRes() throws Exception {
		
		this.roleService.updatePrivilegeRoleService(rolevo,new Object[] {resourceIds}) ;
		
		return "doAssignResRole" ;
	}
	
	
	public String addRole() throws Exception {
		this.roleService.savePrivilegeRoleService(rolevo) ;
		return "add" ;
	}

}
